<template>
	<view>
		<view class="u-f-ajc" v-if="food.count">
			<view class="u-f-ajc">
				<view class="cont" :style="{'margin-top':marginTop + 'rpx'}" @click.stop="decreaseCart(food)">
					<image src="https://zj.gdwrh.com/fnyg/static/images/post-station/des.png" style="width: 46rpx;height: 46rpx;" mode="widthFix"></image>
				</view>
				<text style="padding: 0 25upx;font-size: 16px;">{{food.count}}</text> </view>
			<view :style="{'margin-top':marginTop + 'rpx'}" class="cont"  @click.stop="addCart(food)">
				<image src="https://zj.gdwrh.com/fnyg/static/images/post-station/add2.png" style="width: 46rpx;height: 46rpx;color: #CCCCCC;" mode="widthFix"></image>
			</view>
		</view>
		<view class="addCartBtn round u-f-ac" v-else  @click.stop="addCart(food)">
			<text>加入购物车</text>
		</view>
	</view>
</template>

<script>
	// import Vue from 'vue'
	export default {
		props: {
			// 商品
			food: {type: Object,
			},
			marginTop:{
				type: Number,
				default: 2,
			}
		},
		data() {
			return {
			};
		},
		methods: {
			addCart: function(item) {
				item.count++
				this.$emit('add',item)
			},
			decreaseCart(item) {
				item.count--
				this.$emit('dec',item)
			}
		}
	}
</script>

<style scoped>
	.cont {
		width: 50upx;
		height: 50upx;
		box-sizing: border-box;
		border-radius: 50%;
		text-align: center;
	}
	.addCartBtn{
		display: inline-block;
		background-color: #F22222;
		width: 150upx;
		line-height: 1;
		text-align: center;
		color: #ffffff;
		padding: 12rpx;
		margin: 0 auto;
		font-size: 12px;
	}
</style>
